﻿@model  HANS_BackStage.Model.DbModel.Backstage_admin
@{
    ViewBag.Title = "创建管理员";
    var RoleList = ViewData["AllRoles"] as List<HANS_BackStage.Model.DbModel.Backstage_role>;
    var RoleListSelf = ViewData["MyRole"] as List<HANS_BackStage.Model.DbModel.Backstage_role>;
    var FileUploadModel = ViewData["FaceImag"] as HANS_Base.Model.FileUploadModel;
}

<div class="x_panel">
    <!--beginHead-->
    <div class="x_title">
        <h2>创建管理员 <small>HANS</small></h2>
        <ul class="nav navbar-right panel_toolbox">
            <li>
                <a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
            </li>
        </ul>
        <div class="clearfix"></div>
    </div>
    <!--endHead-->
    <div class="x_content">
        <!--beginForm-->
        @using (Html.BeginForm("CreateAdmin", "Account", FormMethod.Post,
                                                    new { @class = "form-horizontal form-label-left js-form-submit", @novalidate = "", enctype = "multipart/form-data", id = "fileupload" }))
        {
            @Html.AntiForgeryToken()
            <div class="form-group">
                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">
                    头像
                </label>
                <div class="col-md-6 col-sm-6 col-xs-12">
                    <div class=“kv-avatar center-block text-center” style=“ width ：200px ”>
                        <input id="FaceIma" name="FaceIma" type="file" class=“file-loading” required>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">
                    账号<span class="required">*</span>
                </label>
                <div class="col-md-6 col-sm-6 col-xs-12">
                    @Html.TextBoxFor(i => i.Name, new { @class = "form-control col-md-7 col-xs-12", @placeholder = "英文字母开头，5-16" })
                </div>
                @Html.ValidationMessageFor(i => i.Name, null, new { @class = "text-danger" })
            </div>
            <div class="form-group">
                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">
                    密码<span class="required">*</span>
                </label>
                <div class="col-md-6 col-sm-6 col-xs-12">
                    @Html.PasswordFor(i => i.Password, new { @class = "form-control col-md-7 col-xs-12",@placeholder = "英文字母开头6-18" })
                </div>
                @Html.ValidationMessageFor(i => i.Password,null, new { @class = "text-danger" })
            </div>
            <div class="form-group">
                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">
                    昵称<span class="required">*</span>
                </label>
                <div class="col-md-6 col-sm-6 col-xs-12">
                    @Html.TextBoxFor(i => i.Nickname, new { @class = "form-control col-md-7 col-xs-12" })
                </div>
                @Html.ValidationMessageFor(i => i.Nickname, null, new { @class = "text-danger" })
            </div>
            <div class="form-group">
                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">
                    真实姓名<span class="required">*</span>
                </label>
                <div class="col-md-6 col-sm-6 col-xs-12">
                    @Html.TextBoxFor(i => i.Truename, new { @class = "form-control col-md-7 col-xs-12", @placeholder = "中文" })
                </div>
                @Html.ValidationMessageFor(i => i.Truename, null, new { @class = "text-danger" })
            </div>
            <div class="form-group">
                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">
                    性别<span class="required">*</span>
                </label>
                <div class="col-md-6 col-sm-6 col-xs-12">
                    @Html.HiddenFor(i => i.Sex)
                    <select class="form-control js-select-sex" id="sex">
                        <option value="1">男</option>
                        <option value="2">女</option>
                        <option value="0" selected>不详</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">
                    年龄<span class="required">*</span>
                </label>
                <div class="col-md-6 col-sm-6 col-xs-12">
                    @Html.TextBoxFor(i => i.Age, new { @class = "form-control col-md-7 col-xs-12", @type = "number", @min = "0", @max = "100" })
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-3 col-sm-3 col-xs-12">
                    角色
                </label>
                <div class="col-md-6 col-sm-6 col-xs-12">
                    @Html.Hidden("Roles")<!--保存多选的select的值-->
                    <select id="roleSelect" class="form-control js-select2-select js-select-role" multiple="multiple">
                        <!--js-select-role[common js]-->
                        @{
                            foreach (var role in RoleList)
                            {
                                string roleSelectStr = "";
                                if (RoleListSelf.Any(r => r.Rolename == role.Rolename))
                                {
                                    roleSelectStr = "selected=\"selected\"";
                                }
                                <option value="@role.Id" @roleSelectStr>@role.Rolename</option>
                            }
                        }
                    </select>
                </div>
            </div>
            <div class="ln_solid"></div><!--一条横线-->
                            <div class="form-group">
                                <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
                                    <button type="submit" class="btn btn-success">保存</button>
                                    <a href="@HttpContext.Current.Request.UrlReferrer" class="btn btn-default">取消</a>
                                </div>
                            </div>
                            }
        <!--endForm-->
    </div>
</div>
@section Scripts{
    <script type="text/javascript">

        var changeStringRole = { selectClass: ".js-select-role", selectValString: "#Roles" };
        $('.js-select-role').change(changeStringRole, SetChangeSelectString);//角色更改赋值

        var changeStringSex = { selectClass: ".js-select-sex", selectValString: "#Sex" };
        $('.js-select-sex').change(changeStringSex, SetChangeSelectString);//性别更改赋值
        $('#FaceIma').fileinput(@Html.Raw(FileUploadModel.ToJson()));
    </script>
<script type="text/javascript">
        
</script>
}

